/**
 * model.h is part of cbs-framework.
 *
 * cbs-framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * cbs-framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with cbs-framework.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MODEL_H
#define MODEL_H

#include "../utils/visitor/visitable.h"
#include "../utils/printable.h"
#include "definitions.h"
#include <vector>

// Forward declarations.
class Task;
class Constraint;
class Resource;

// Typedefs.
typedef std::vector< std::pair< tCallback, void *  > > tCallbacks;

typedef enum
{
    ON_ADD_CONSTRAINT_CALLBACK,
    ON_REMOVE_CONSTRAINT_CALLBACK,
    ON_ADD_TASK_CALLBACK,
    ON_REMOVE_TASK_CALLBACK,
    ON_ADD_RESOURCE_CALLBACK,
    ON_REMOVE_RESOURCE_CALLBACK,
    N_CALLBACKS
} tModelCallback;

class Model : public Visitable, public Printable
{
public:

    Model( const std::string & a_modelName = UNNAMED_MODEL );

    virtual ~Model();

    virtual void Accept( Visitor * a_visitor );

    virtual std::string Print() const;

    void Add( Task * a_task );

    std::size_t NTasks() const;

    void Add( Constraint * a_constraint );

    std::size_t NConstraints() const;

    void Add( Resource * a_resource );

    std::size_t NResources() const;

    void ModelName( const std::string & a_modelName );

    const std::string & ModelName() const;

    void Subscribe( tCallback a_callback, void * a_object, tModelCallback a_modelCallback );

private:

    // Fields
    // ------

    tTasks          m_tasks;
    std::string     m_modelName;
    tConstraints    m_constraints;
    tResources      m_resources;

    tCallbacks m_callbacks [ N_CALLBACKS ];

    static const std::string UNNAMED_MODEL;

    // Methods
    // -------

    void Clear();
    void ClearTasks();
    void ClearConstraints();
    void ClearResources();

    void AcceptTasks( Visitor * a_visitor );
    void AcceptConstraints( Visitor * a_visitor );
    void AcceptResources( Visitor * a_visitor );

    std::string PrintTasks() const;
    std::string PrintConstraints() const;
    std::string PrintResources() const;

    void Notify( tModelCallback a_callback, void * a_param );

    // Protect default copy constructor.
    Model( const Model & a_other );

    // Protect default operator =
    Model & operator = ( const Model & a_other );
};

#endif // MODEL_H
